#include "chechintable.h"
#include "ui_chechintable.h"

#include <QSqlQuery>
#include<QMessageBox>
#include<QSqlQueryModel>
#include"slogin.h"
#include"student.h"
#include "formsclass.h"

ChechinTable::ChechinTable(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChechinTable)
{
    ui->setupUi(this);
}

ChechinTable::~ChechinTable()
{
    delete ui;
}
 void ChechinTable::showchechinW()
 {
     emit signalscheckinW();
     this->show();
 }
  void ChechinTable::showsloginW()
  {
     SLogin *slw = new SLogin;
      slw->show();
  }
  void ChechinTable::showstudentW()
  {
      Student *stw = new Student;
      stw->show();
  }
 void ChechinTable::selectBoxSlot(const QString &XID,const QString &ScienceID,
                                  const QString &teacherId,const QString &Classid,
                                  const QString &RoomID,const QString &CheckinTime,const QString &xuehao)//查询箱子状态
 {
     bool ok = connectsqliteS.ok;
     if(ok)
     {
         QSqlQueryModel *model = new QSqlQueryModel(ui->tableView_C);

         model->setQuery(QString("select * from CheckinInfoTable where XID = '%1' and "
                                 "ScienceID = '%2' and teacherId = '%3' and Classid = '%4' and RoomID='%5' and "
                                 "CheckinTime = '%6' and  xuehao = '%7';").arg(XID).arg(ScienceID).arg(teacherId)
                         .arg(Classid).arg(RoomID).arg(CheckinTime).arg(xuehao));
         //列名
         model->setHeaderData(0, Qt::Horizontal, tr("XID"));
         model->setHeaderData(1, Qt::Horizontal, tr("ScienceID"));
         model->setHeaderData(2, Qt::Horizontal, tr("teacherId"));
         model->setHeaderData(3, Qt::Horizontal, tr("Classid"));
         model->setHeaderData(4, Qt::Horizontal, tr("RoomID"));
         model->setHeaderData(5, Qt::Horizontal, tr("CheckinTime"));
         model->setHeaderData(6, Qt::Horizontal, tr("xuehao"));

         ui->tableView_C->setModel(model);//数据放置进去
         ui->tableView_C->verticalHeader()->hide();//不显示序号
     }
     else
     {
         QMessageBox::warning(this,"错误","未连接，请检查.");
     }
 }

void ChechinTable::on_commandLinkButton_clicked()
{
    this->hide();
    this->showsloginW();
}

void ChechinTable::on_pb_rememberface_clicked()
{
    this->hide();
    this->showstudentW();
}

void ChechinTable::on_pushButton_clicked()
{
//    bool ok = connectsqliteS.ok;
//    if(ok)
//    {
//        QSqlQueryModel *model = new QSqlQueryModel(ui->tableView_N);

//        model->setQuery(QString("select count * as  xuehao from table1 (select * from CheckinInfoTable "
//                                "where XID = '%1' and ScienceID = '%2' and teacherId = '%3' and Classid = '%4' and RoomID='%5' and "
//                                "CheckinTime = '%6';").arg(m_xid).arg(m_ScienceID).arg(m_teacherId)
//                            .arg(m_Classid).arg(m_RoomID).arg(m_CheckinTime));
//        //列名
//        model->setHeaderData(0, Qt::Horizontal, tr("xuehao"));

//        ui->tableView_N->setModel(model);//数据放置进去
//        ui->tableView_N->verticalHeader()->hide();//不显示序号
//    }
//    else
//    {
//        QMessageBox::warning(this,"错误","未连接，请检查.");
//    }

}
